public class c3 {
    //    static int arr[] = new int[5];
//    public static void main(String a[]) {
//        System.out.println(arr[0]);
//    }
//}
//}
import java.util.Scanner;

    public class Main {
        public static void main(String[] args) {
            // 创建Scanner对象以获取用户输入
            Scanner scanner = new Scanner(System.in);

            // 读取三位小伙伴的年龄
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            int z = scanner.nextInt();

            // 调用方法计算最早几年后可以相聚
            int years = findReunionYear(x, y, z);

            // 输出结果
            if (years == -1) {
                System.out.println("so sad!");
            } else {
                System.out.println(years);
            }

            // 关闭scanner
            scanner.close();
        }

        private static int findReunionYear(int x, int y, int z) {
            for (int n = 1; n <= 100; n++) {
                int newX = x + n;
                int newY = y + n;
                int newZ = z + n;

                // 获取年龄末尾数字
                int lastDigitX = newX % 10;
                int lastDigitY = newY % 10;
                int lastDigitZ = newZ % 10;

                // 检查末尾数字是否分别为3、6、9
                if (lastDigitX == 3 && lastDigitY == 6 && lastDigitZ == 9) {
                    return n;
                }
                if (lastDigitX == 3 && lastDigitY == 9 && lastDigitZ == 6) {
                    return n;
                }
                if (lastDigitX == 6 && lastDigitY == 3 && lastDigitZ == 9) {
                    return n;
                }
                if (lastDigitX == 6 && lastDigitY == 9 && lastDigitZ == 3) {
                    return n;
                }
                if (lastDigitX == 9 && lastDigitY == 3 && lastDigitZ == 6) {
                    return n;
                }
                if (lastDigitX == 9 && lastDigitY == 6 && lastDigitZ == 3) {
                    return n;
                }
            }
            // 如果100年内都无法满足条件
            return -1;
        }
    }